#!/usr/bin/python3
# -*- encoding=utf-8 -*-

import requests
import user

class Resource:

    def __init__(self,headers,session):  #构造函数
        self.headers = headers
        self.session = session

    def listResource(self,start,limit):
        url = 'http://172.99.1.102:6080/resource/listResource.action?start=%s&limit=%s'%(start,limit)
        req = self.session.get(url,headers=self.headers)
        return req
        
    def listResourceByName(self,resourceName):
        
        url = 'http://172.99.1.102:6080/resource/listResource.action?resourceName=%s'%resourceName
        req = self.session.get(url,headers=self.headers)
        return req
    
    def listResourceIdByName(self,resourceName):

        req = self.listResourceByName(resourceName)
        text = req.text
        num = text.find('"id"')
        resourceId = text[num+5:num+16]
        return resourceId

 
    def getResourceById(self,resourceId):

        url = 'http://172.99.1.102:6080/resource/getResource.action?resourceId=%s'%resourceId
        req = self.session.get(url,headers=self.headers)
        return req

       
    

